{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ea0cf75c",
   "metadata": {},
   "source": [
    "# 环境配置\n",
    "\n",
    "同济子豪兄 2023-8-19"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "efa7fd67",
   "metadata": {},
   "source": [
    "## 安装基础工具包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10379310",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install numpy pandas matplotlib tqdm opencv-python pillow onnx --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a5195a33",
   "metadata": {},
   "source": [
    "## 安装推理框架ONNX Runtime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1516de8d",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install onnxruntime -i https://pypi.tuna.tsinghua.edu.cn/simple"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c2045954",
   "metadata": {},
   "source": [
    "## 验证安装成功"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a8fabc76",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ONNXRuntime 版本 1.14.1\n"
     ]
    }
   ],
   "source": [
    "import onnxruntime as ort\n",
    "print('ONNXRuntime 版本', ort.__version__)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bfa20d2c",
   "metadata": {},
   "source": [
    "## 下载待测图像和视频文件至当前文件夹"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a827ca55",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 西瓜图片和视频，拍摄人：田文博\n",
    "\n",
    "!wget https://zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com/20230130-mmseg/watermelon/data/watermelon_test1.jpg\n",
    "\n",
    "!wget https://zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com/20230130-mmseg/watermelon/data/video_watermelon_3.mov"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c56feff",
   "metadata": {},
   "source": [
    "## 下载MMDeploy导出的ONNX模型文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "53f67610",
   "metadata": {},
   "outputs": [],
   "source": [
    "# # 删除原有的模型目录（如有）\n",
    "# !rm -rf mmseg2onnx_fastscnn mmseg2onnx_fastscnn.zip\n",
    "\n",
    "# # 下载压缩包\n",
    "# !wget https://zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com/20230130-mmseg/watermelon/ckpt/mmseg2onnx_fastscnn.zip\n",
    "\n",
    "# # 解压\n",
    "# !unzip mmseg2onnx_fastscnn.zip >> /dev/null\n",
    "\n",
    "# # 删除压缩包\n",
    "# !rm -rf mmseg2onnx_fastscnn.zip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e52c125d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--2023-09-03 03:39:56--  https://zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com/20230130-mmseg/watermelon/ckpt/mmseg2onnx_fastscnn_static.zip\n",
      "Resolving zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com (zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com)... 121.36.235.132\n",
      "Connecting to zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com (zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com)|121.36.235.132|:443... connected.\n",
      "HTTP request sent, awaiting response... 200 OK\n",
      "Length: 21458418 (20M) [application/zip]\n",
      "Saving to: ‘mmseg2onnx_fastscnn_static.zip’\n",
      "\n",
      "mmseg2onnx_fastscnn 100%[===================>]  20.46M  11.7MB/s    in 1.7s    \n",
      "\n",
      "2023-09-03 03:39:58 (11.7 MB/s) - ‘mmseg2onnx_fastscnn_static.zip’ saved [21458418/21458418]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 删除原有的模型目录（如有）\n",
    "!rm -rf mmseg2onnx_fastscnn_static.zip mmseg2onnx_fastscnn_static\n",
    "\n",
    "# 下载压缩包\n",
    "!wget https://zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com/20230130-mmseg/watermelon/ckpt/mmseg2onnx_fastscnn_static.zip\n",
    "\n",
    "# 解压\n",
    "!unzip mmseg2onnx_fastscnn_static.zip >> /dev/null\n",
    "\n",
    "# 删除压缩包\n",
    "!rm -rf mmseg2onnx_fastscnn_static.zip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a85c1f45",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
